//
//  YSRequest.h
//  Pods
//
//  Created by zhanglu on 16/3/3.
//
//

#import "YSRequestConfig.h"

#import <AFNetworking/AFNetworking.h>

//FOUNDATION_EXPORT void YSAFLog(NSString *format, ...) {
//#ifdef DEBUG
//    va_list argptr;
//    va_start(argptr, format);
//    NSLogv(format, argptr);
//    va_end(argptr);
//#endif
//}
NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, YSRequestMethod) {
    YSRequestMethodGet = 0,
    YSRequestMethodPost,
    YSRequestMethodHead,
    YSRequestMethodPut,
    YSRequestMethodDelete,
    YSRequestMethodPatch
};

typedef NS_ENUM(NSInteger, YSRequestSerializerType) {
    YSRequestSerializerTypeHTTP = 0,
    YSRequestSerializerTypeJSON,
};


typedef NS_ENUM(NSInteger, YSResponseSerializerType) {
    YSResponseSerializerTypeHTTP = 0,
    YSResponseSerializerTypeJSON,
};
@class YSRequestManager;
@interface YSRequest : NSObject

@property (nonatomic, strong) NSURLSessionDataTask *sessionDataTask;
@property (nonatomic, copy) NSString *requestUrl;
@property (nonatomic, assign) YSRequestMethod requestMethod;
@property (nonatomic, assign) YSRequestSerializerType requestSerializerType; /**< 默认 HTTP */
@property (nonatomic, assign) YSResponseSerializerType responseSerializerType; /**< 默认 JSON */
@property (nonatomic, copy) NSDictionary *requestParam;
@property (nonatomic, assign) NSTimeInterval timeoutInterval;
@property (nonatomic, strong) NSError *error;
@property (nonatomic, strong, nullable) NSHTTPURLResponse *response;
@property (nonatomic, strong, readonly, nullable) NSNumber *responseStatusCode;
@property (nonatomic, strong, readonly, nullable) NSDictionary *responseHeaders;

/**
 * name是这样的@"Common.login"
 */
+ (NSURL *)urlWithName:(NSString *)pathName;//name不语义和urlWithCategory:(NSString *) category AndName: (NSString *)name有冲突，但是报纸一致性
+ (instancetype)requestWithURLString:(NSString *)urlString AndRequestMethod:(YSRequestMethod)requestMethod;
+ (instancetype)requestWithNSURL:(NSURL *)url AndRequestMethod:(YSRequestMethod)requestMethod;

+ (instancetype)requestWithURL:(NSString *)urlString AndMethod:(NSString *)methodString;
+ (instancetype)requestWithCategory:(NSString *)category AndName:(NSString *)name;
+ (instancetype)requestWithName:(NSString *)name;

// 上传图片相关
@property (nonatomic, strong, readonly) UIImage *image;
@property (nonatomic, strong, readonly) NSData *imageData;
@property (nonatomic, assign, readonly) CGFloat imageCompressionQuality;
@property (nonatomic, copy, readonly) NSString *imageName;
@property (nonatomic, copy, readonly) NSString *imageType;

+ (instancetype)requestWithName:(NSString *)name image:(UIImage *)image;
/**
 *  上传单张图片
 *
 *  @param image              image description
 *  @param compressionQuality 压缩率
 *  @param imageName          图片名称
 *  @param imageType          图片类型
 */
+ (instancetype)requestWithName:(NSString *)name image:(UIImage *)image
             compressionQuality:(CGFloat)compressionQuality
                      imageName:(NSString *)imageName
                      imageType:(NSString *)imageType;

+ (instancetype)requestWithName:(NSString *)name imageData:(NSData *)imageData;

+ (instancetype)requestWithName:(NSString *)name imageData:(NSData *)imageData
                      imageName:(NSString *)imageName
                      imageType:(NSString *)imageType;

- (void)sendWithParameters:(NSDictionary *) params
                   success:(nullable void(^)(id response))success
                   failure:(nullable void(^)(YSRequest * request))failure;

/**< 设置delegate后，可在一定条件下实现请求自动取消 */
- (void)sendWithParameters:(NSDictionary *) params
                  delegate:(nullable id)delegate
                   success:(nullable void(^)(id response))success
                   failure:(nullable void(^)(YSRequest * request))failure;

// 撤销请求
- (void)cancle;

+ (NSString *)requestMethodString:(YSRequestMethod)method;

@end
NS_ASSUME_NONNULL_END
